home *** CD-ROM | disk | FTP | other *** search
/ Alles Voor Internet / Tout Pour Internet / alles voor internet.iso / MacInternet™ / Telnet / Terminal 2.2 / Project / Sources / MySF.c < prev    next >
Text File  |  1992-01-17  |  5KB  |  189 lines

  1. /*
  2.     Terminal 2.2
  3.     "MySF.c"
  4. */
  5.  
  6. #ifdef THINK_C
  7. #include "MacHeaders"
  8. #endif
  9. #ifdef applec
  10. #pragma load ":(Objects):MacHeadersMPW"
  11. #pragma segment Main2
  12. #endif
  13.  
  14. #include "MySF.h"
  15. #include "Strings.h"
  16. #include "Utilities.h"
  17. #include "Text.h"
  18. #include "Main.h"
  19. #include "Document.h"
  20.  
  21. static Byte *DialogOpenSave;    /* Text for Open/Save button */
  22. static Byte *Suffix;            /* File name suffix */
  23. static OSType Creator;            /* Creator nor wanted in SFGetFile */
  24.  
  25. /* ----- File filter for SF -------------------------------------------- */
  26.  
  27. static pascal Boolean MyFileFilter(register ParamBlockRec *pb)
  28. {
  29.     if (Creator && pb->fileParam.ioFlFndrInfo.fdCreator == Creator)
  30.         return TRUE;
  31.     return Suffix ?
  32.         !CheckSuffix((Byte *)pb->fileParam.ioNamePtr,
  33.             Suffix) : FALSE;
  34. }
  35.  
  36. #ifdef OUTLINE
  37. /* ----- Filter function for SF modal dialog --------------------------- */
  38.  
  39. /* Outline Open/Save button */
  40.  
  41. static pascal Boolean MyFilter(dialog, event, item)
  42. register DialogPtr dialog;
  43. register EventRecord *event;
  44. short *item;
  45. {
  46. #pragma unused(item)
  47.     DialogPtr dp;
  48.     short i;
  49.  
  50.     if (event->what == updateEvt) {
  51.         /* Proper handling of update events to avoid continous calls
  52.         to our filter function with update events (flickering):
  53.         Other dialog boxes may appear on the screen and disappear,
  54.         generating update events both for themselves and for other
  55.         windows allready on the screen. They must be handled
  56.         immediatly  and then cleared via BeginUpdate() / EndUpdate().
  57.         Otherwise the system will keep reporting the same event over
  58.         and over again. */
  59.         if (!SystemEvent(event)) {    /* SystemEvent() does updating */
  60.             if (IsDialogEvent(event)) {            /* Dialog Window? */
  61.                 DialogSelect(event, &dp, &i);    /* Update dialog */
  62.                 if (dp == dialog)                /* If our dialog */
  63.                     OutLine(dialog, 1, patCopy);/* "Ok" button */
  64.             } else
  65.                 RedrawDocument();        /* Update application window */
  66.         }
  67.     }
  68.     return FALSE;    /* ModalDialog() should handle event */
  69. }
  70. #else
  71. #define MyFilter 0
  72. #endif
  73.  
  74. /* ----- SF Dialog Hook ------------------------------------------------ */
  75.  
  76. static pascal short MyHook(
  77.     register short itemno,
  78.     register DialogPtr dialog)
  79. {
  80.     short type;
  81.     Handle item;
  82.     Rect box;
  83.  
  84.     if (itemno == -1 && DialogOpenSave) {
  85.         /* Set text of Open/Save button */
  86.         GetDItem(dialog, getOpen, &type, &item, &box);
  87.         SetCTitle((ControlHandle)item, DialogOpenSave);
  88.     }
  89.     return itemno;
  90. }
  91.  
  92. /* ----- Get a file ---------------------------------------------------- */
  93.  
  94. void MySFGetFile(
  95.     register Byte *open,            /* Text for "Open" button */
  96.     register Byte *suffix,            /* File name suffix required */
  97.     register short numTypes,
  98.     register OSType *typeList,
  99.     register SFReply *reply,
  100.     OSType creator)                    /* Creator NOT wanted */
  101. {
  102.     Point where;
  103.  
  104.     DialogOpenSave = open;
  105.     Suffix = suffix;
  106.     Creator = creator;
  107.     GetDlogOrigin(getDlgID, &where);
  108.     SFPGetFile(where,
  109.         (void *)EmptyStr,
  110.         (FileFilterProcPtr)MyFileFilter,
  111.         numTypes,
  112.         (void *)typeList,
  113.         (DlgHookProcPtr)MyHook,
  114.         reply,
  115.         getDlgID,
  116.         (ModalFilterProcPtr)MyFilter);
  117. }
  118.  
  119. /* ----- Put a file ---------------------------------------------------- */
  120.  
  121. void MySFPutFile(
  122.     register Byte *save,            /* Text for "Save" button */
  123.     register Byte *prompt,            /* Prompt text */
  124.     register Byte *name,            /* Default file name */
  125.     register SFReply *reply)
  126. {
  127.     Point where;
  128.  
  129.     DialogOpenSave = save;
  130.     GetDlogOrigin(putDlgID, &where);
  131.     SFPPutFile(where, prompt, name, MyHook, reply, putDlgID, MyFilter);
  132. }
  133.  
  134. /* ----- Select a directory -------------------------------------------- */
  135.  
  136. static pascal Boolean NoFileFilter(register ParmBlkPtr p)
  137. {
  138.     /* Normally, folders are ALWAYS shown, and aren't even passed to
  139.     this file filter for judgement. Under such circumstances, it is    
  140.     only necessary to blindly return TRUE (allow no files whatsoever).
  141.     However, Standard File is not documented in such a manner, and
  142.     this feature may not be TRUE in the future. Therefore, we DO check
  143.     to see if the entry passed to us describes a file or a directory. */
  144.  
  145.     return (p->fileParam.ioFlAttrib & 0x10) == 0;
  146. }
  147.  
  148. static pascal short DirectoryHook(
  149.     register short itemno,
  150.     register DialogPtr dialog)
  151. {
  152.     short type;
  153.     Handle item;
  154.     Rect box;
  155.     Point where;
  156.  
  157.     if (itemno == -1) {
  158.         /* Set text of "Open" button */
  159.         GetDItem(dialog, getOpen, &type, &item, &box);
  160.         SetCTitle((ControlHandle)item, MyString(STR_G, G_SELECT));
  161.     } else if (itemno == 103) {
  162.         /* Double click on folder name or "Select" clicked */
  163.         GetDItem(dialog, 7,  &type, &item, &box);
  164.         GetMouse(&where);
  165.         if (!PtInRect(where, &box))
  166.             itemno = 1;        /* Treat like file open */
  167.     }
  168.     return itemno;
  169. }
  170.  
  171. Boolean SelectDirectory(
  172.     short *volume,
  173.     long *directory)
  174. {
  175.     Point where;
  176.     SFReply reply;
  177.  
  178.     GetDlogOrigin(getDlgID, &where);
  179.     SFPGetFile(where, (void *)EmptyStr, (FileFilterProcPtr)NoFileFilter, 1,
  180.         (void *)"!@#$", (DlgHookProcPtr)DirectoryHook, &reply, getDlgID,
  181.         (ModalFilterProcPtr)MyFilter);
  182.     if (reply.good) {
  183.         *volume = -SFSaveDisk;
  184.         *directory = reply.fType;
  185.         /* *directory = CurDirStore; */
  186.     }
  187.     return reply.good;
  188. }
  189.